/**
 * Created by Ysssssss on 2021/4/14.
 */

import React, { useCallback } from 'react'
import {Menu, Dropdown} from "antd";

const DropdownMenu = props => {
    const { dropdownList = [], onClick, trigger='click', children, staticContext, ..._props } = props
    const handleClick = useCallback((e) => {
        e.domEvent.stopPropagation();
        e.domEvent.preventDefault();
        onClick && onClick(e.key)
    }, [onClick])

    const menu = (
        <Menu onClick={handleClick}>
            {
                dropdownList.map(item => (
                    <Menu.Item key={item.key}>{item.name}</Menu.Item>
                ))
            }
        </Menu>
    )
    return (
        <Dropdown overlay={menu} trigger={trigger} { ..._props }>
            {children}
        </Dropdown>
    )
}

export default DropdownMenu